/*
 * GF_C_MODEL_STRING_LIKE_LIST_20240913/EXAMPLES/EXAMPLES_STRING_TOKENS.c
 * Created by GF on 2024/09/13.
 */

#include <stdio.h>
#include <string.h> /* memset(); strcmp(); strcpy(); strlen(); strtok();*/
#include <malloc.h> /* malloc(); */
#include "../GF_C_MODEL_STRING_LIKE_LIST.h"

/* free(); */

int main(int argc, char *argv[]) {

    char Example_String_1[8]  = "A,B;C:D";
    char Example_String_2[11] = "A,;B;:C:,D";
    char Example_String_3[8]  = "A,B,C,D";
    char Example_String_4[11] = "A--B--C--D";
    char Example_String_5[8]  = "1,2,3,4";
    char Example_String_6[11] = "1--2--3--4";
    
    char* Token;
    
    printf("**************************************************\n");
    printf("Examples (strtok):\n");
    Token = strtok(Example_String_3, ",");
    printf("Expect: \"A,B,C,D\" => \"A\" | Output: %s\n", Token);
    Token = strtok(NULL, ",");
    printf("Expect: \"A,B,C,D\" => \"B\" | Output: %s\n", Token);
    Token = strtok(NULL, ",");
    printf("Expect: \"A,B,C,D\" => \"C\" | Output: %s\n", Token);
    Token = strtok(NULL, ",");
    printf("Expect: \"A,B,C,D\" => \"D\" | Output: %s\n", Token);
    Token = strtok(Example_String_2, ",;:");
    printf("Expect: \"A,;B;:C:,D\" => \"A\"      | Output: %s\n", Token);
    Token = strtok(NULL, ",");
    printf("Expect: \"A,;B;:C:,D\" => \";B;:C:\" | Output: %s\n", Token);
    Token = strtok(NULL, ",");
    printf("Expect: \"A,;B;:C:,D\" => \"D\"      | Output: %s\n", Token);
    
    Token = strtok(NULL, ",");
    printf("Expect: (null) => (null) | Output: %s\n", Token);
    
    printf("**************************************************\n");
    printf("Examples (STRING_TOKENS_REVERSE):\n");
    Token = STRING_TOKENS_REVERSE(Example_String_1, ",;:");
    printf("Expect: \"A,B;C:D\" => \"D\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE(NULL, ",;:");
    printf("Expect: \"A,B;C:D\" => \"C\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE(NULL, ",;:");
    printf("Expect: \"A,B;C:D\" => \"B\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE(NULL, ",;:");
    printf("Expect: \"A,B;C:D\" => \"A\" | Output: %s\n", Token);
    
    Token = strtok(NULL, ",");
    printf("Expect: (null) => (null) | Output: %s\n", Token);
    
    printf("**************************************************\n");
    printf("Examples (STRING_TOKENS_REVERSE_BY_STRING):\n");
    Token = STRING_TOKENS_REVERSE_BY_STRING(Example_String_4, "--");
    printf("Expect: \"A--B--C--D\" => \"D\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: \"A--B--C--D\" => \"C\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: \"A--B--C--D\" => \"B\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: \"A--B--C--D\" => \"A\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(Example_String_6, "--");
    printf("Expect: \"1--2--3--4\" => \"4\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: \"1--2--3--4\" => \"3\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: \"1--2--3--4\" => \"2\" | Output: %s\n", Token);
    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: \"1--2--3--4\" => \"1\" | Output: %s\n", Token);

    Token = STRING_TOKENS_REVERSE_BY_STRING(NULL, "--");
    printf("Expect: (null) => (null) | Output: %s\n", Token);
    
    free(Token);

    return 0;
}
